#include "mainsense.h"
#include "ui_mainsense.h"
#include "qaction.h"
#include <QPainter>
#include <mypushbutton.h>
#include <QDebug>
#include <QTimer>
#include <QSound>
MainSense::MainSense(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainSense)
{
    ui->setupUi(this);

    //配置主场景

    //设置固定大小
    setFixedSize(600,888);

    //设置图标
    setWindowIcon(QIcon(":/new/prefix1/res/Coin0001.png"));

    //设置标题
    setWindowTitle("翻金币游戏");

    //退出按钮的实现
    connect(ui->actionQuit,&QAction::triggered,[=](){
         this->close();
      });

    //准备开始按钮的音效
    QSound *startSound = new QSound(":/new/prefix1/res/TapButtonSound.wav");

    //开始按钮
    MyPushButton *startBtn = new MyPushButton(":/new/prefix1/res/MenuSceneStartButton.png");
    startBtn->setParent(this);
    startBtn->move(this->width()*0.5-startBtn->width()*0.5,this->height()*0.6);

    //实例化选择关卡场景
    chooseScene =new ChooseLevelScene;

    //监听选择关卡的返回按钮的信号
    connect(chooseScene,&ChooseLevelScene::ChooseSceneBack,this,[=]{
        this->setGeometry(chooseScene->geometry());
        chooseScene->hide();//将选择关卡场景隐藏
        this->show();
    });

    connect(startBtn,&MyPushButton::clicked,[=](){
        //qDebug()<<"点击了开始";

        //播放开始音效资源
//        startSound->setLoops(-1);
        startSound->play();

        //做弹起特效
        startBtn->zoom1();
        startBtn->zoom2();

        //延时进入到选择关卡场景中
        QTimer::singleShot(500,this,[=](){
            //设置chooseScene场景的位置
            chooseScene->setGeometry(this->geometry());
            //自身隐藏
            this->hide();
            //显示选择关卡的场景
            chooseScene->show();
        });
    });
}

void MainSense::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    QPixmap pix;
    pix.load(":/new/prefix1/res/PlayLevelSceneBg.png");
    painter.drawPixmap(0,0,600,888,pix);

    //画背景上的图标
    pix.load(":/new/prefix1/res/Title.png");

    //缩放图标
    //pix=pix.scaled(pix.width()*0.5,pix.height()*0.5);

    painter.drawPixmap(10,30,pix);
}
MainSense::~MainSense()
{
    delete ui;
}

